package chapter03.Demo3;

/**
 * 1.this关键字
 *   Student区间内this指Student类本身
 *   使用this可以使用类的其他属性和方法
 * 2.static关键字
 */
class Student {
    String id;
    String name;
    private int age;
    private int gender;// 0男 1女
    String dep = "信息系";
    static  String hobby = "玩csgo的马庆";

    public Student(String ID){
        id = ID;
    }

    public  Student(){

    }

    void read() {
        System.out.println("大家好，我是" + name + ".我在看书");
    }

    void setAge(int age) {//设置年龄
//        this.age = age;//Student区间内this指Student 类本身
        if (age < 0 || age > 150) {
            System.out.println("你输入的年龄有误");
        } else {
            this.age = age;
        }
    }

    int getAge() {// 获取年龄
        return age;
    }

    // 转化性别汉字到数字
    void setGender(String g) {
        if (g.equals("男")) {//String类型判断字符相等固定格式
            gender = 0;
        } else {
            System.out.println("性别有误");
        }
    }
    String getGender() {
        if (gender == 0) {
            return "男";
        }else {
            return "女";
        }
    }
}

public class demo3 {
    public static void main(String[] args) {
        Student stu1 = new Student();
        stu1.setAge(18);
        Student stu2 = new Student();
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        stu1.dep = "马庆系";
        System.out.println("修改stu1后系部信息");
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        System.out.println("******************");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
        stu1.hobby = "玩火影的马庆";
        System.out.println("学生1爱好static属性变化");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
    }
}
